package ch.fusun.baron.map;

/**
 * A representation of a tile on a map
 */
public class Tile {

	private int x;
	private int y;

	/**
	 * Kryonet constructor
	 */
	public Tile() {
		// Do nothing
	}

	/**
	 * Constructor
	 * 
	 * @param x
	 *            The x coordinate
	 * @param y
	 *            The y coordinate
	 */
	public Tile(int x, int y) {
		this.x = x;
		this.y = y;
	}

	@Override
	public int hashCode() {
		return x + y;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Tile) {
			return (((Tile) obj).x == x) && (((Tile) obj).y == y);
		}
		return false;
	}

	/**
	 * @return X position
	 */
	public int getX() {
		return x;
	}

	/**
	 * @return Y position
	 */
	public int getY() {
		return y;
	}

	@Override
	public String toString() {
		return "[" + x + "," + y + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}

	/**
	 * @param destination
	 *            The destination tile
	 * @return The distance to that tile (geometric)
	 */
	public double absoluteDistanceTo(Tile destination) {
		if (destination != null) {
			return Math.sqrt(Math.pow((this.getX() - destination.getX()), 2)
					+ Math.pow((this.getY() - destination.getY()), 2));
		}
		return Double.MAX_VALUE;
	}

}
